<template>
    <div class="img-skeleton">
        <div class="skeleton_box" :style="'width:'+width+'px;height:'+height+'px;'">
            <div class="skeleton_img_item" :class="{ani_img_class:ani,text_true:text,text_false:!text}">
                <i class="bi bi-image"></i>
            </div>
            <div class="row_1"></div>
            <div class="row_2_1"></div>
            <div class="row_2_2"></div>
        </div>
        
    </div>
</template>
<script>
import { ref } from 'vue'
export default {
    name:'g-img-skeleton',
    props:{
        ani:{
            type:Boolean,
            default:false
        },
        width:{
            type:Number,
            default:300
        },
        height:{
            type:Number,
            default:300
        },
        text:{
            type:Boolean,
            default:true
        }
    },
    setup(props) {
        let ani = ref(props.ani);
        let width = ref(props.width);
        let height = ref(props.text?props.height+50:props.height)
        return {
            width,
            height,
            ani
        }
    }
}
</script>
<style scoped>
    .img-skeleton{
        width: 100%;
        padding: 10px 0;
        margin: 0px 0;
        position: relative;
    }

    .skeleton_box{
        width: 300px;
        height: 350px;
        overflow: hidden;
    }

    .skeleton_img_item {
        width: 100%;
        background: linear-gradient(to left, #e6e6e6, #fcfcfc);
        background-size: 400% 400%;
        border-radius: 3px;
        position: relative;
    }
    .text_true{
        height: calc(100% - 50px);
    }
    .text_false{
        height: 100%;
    }
    .skeleton_img_item i{
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        color: #c7c7c7;
        font-size: 50px;
    }
    .ani_img_class{
        animation: skeleton_img_ani 3.5s ease infinite;
    }

    /* 动画，控制背景 background-position */
    @keyframes skeleton_img_ani {
        0% {background-position: 0% 0%;}
        50% {background-position: 100% 0%;}
        100% {background-position: 00% 0%;}
    }

    .row_1{
        width: 100%;
        height: 15px;
        border-radius: 3px;
        background-color: #e6e6e6;
        margin-top: 10px;
        margin-bottom: 10px;
    }
    .row_2_1{
        width: 70%;
        height: 15px;
        border-radius: 3px;
        background-color: #e6e6e6;
        display: inline-block;
        margin-right: 5%;
    }
    .row_2_2{
        width: 25%;
        height: 15px;
        border-radius: 3px;
        background-color: #e6e6e6;
        display: inline-block;
    }

</style>